home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.AbstractButton;
- import com.sun.java.swing.ButtonModel;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.plaf.ComponentUI;
- import com.sun.java.swing.plaf.basic.BasicButtonListener;
- import com.sun.java.swing.plaf.basic.BasicButtonUI;
- import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Rectangle;
-
- public class MetalButtonUI extends BasicButtonUI {
- private static final MetalButtonUI metalButtonUI = new MetalButtonUI();
-
- protected BasicButtonListener createListener(JComponent c) {
- return new MetalButtonListener((AbstractButton)c);
- }
-
- public static ComponentUI createUI(JComponent c) {
- return metalButtonUI;
- }
-
- protected Color getDisabledTextColor() {
- return UIManager.getColor("Button.disabledText");
- }
-
- protected Color getFocusColor() {
- return UIManager.getColor("Button.focus");
- }
-
- protected Color getSelectColor() {
- return UIManager.getColor("Button.pressed");
- }
-
- public void installUI(JComponent c) {
- super.installUI(c);
- c.setOpaque(true);
- }
-
- protected void paintButtonPressed(Graphics g, AbstractButton b) {
- if (((JComponent)b).isOpaque()) {
- Dimension size = ((Component)b).getSize();
- g.setColor(this.getSelectColor());
- g.fillRect(0, 0, size.width, size.height);
- }
-
- }
-
- protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
- Rectangle focusRect = new Rectangle();
- String text = b.getText();
- boolean isIcon = b.getIcon() != null;
- if (text != null & !text.equals("")) {
- if (!isIcon) {
- focusRect.setBounds(textRect);
- } else {
- focusRect.setBounds(iconRect.union(textRect));
- }
- } else if (isIcon) {
- focusRect.setBounds(iconRect);
- }
-
- g.setColor(this.getFocusColor());
- g.drawRect(focusRect.x - 1, focusRect.y - 1, focusRect.width + 1, focusRect.height + 1);
- }
-
- protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
- AbstractButton b = (AbstractButton)c;
- ButtonModel model = b.getModel();
- FontMetrics fm = g.getFontMetrics();
- if (model.isEnabled()) {
- g.setColor(((Component)b).getForeground());
- BasicGraphicsUtils.drawString(g, text, model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());
- } else {
- g.setColor(UIManager.getColor("Button.disabledText"));
- BasicGraphicsUtils.drawString(g, text, model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());
- }
-
- }
- }
-